package com.example.design.strategy;

/**
 * 上下文类 - 购物车
 */
public class ShoppingCart {
    private DiscountStrategy discountStrategy;
    public ShoppingCart(DiscountStrategy discountStrategy) {
        this.discountStrategy = discountStrategy;
    }
    public double calculateTotalPrice(double price) {
        return discountStrategy.applyDiscount(price);
    }
    public void setDiscountStrategy(DiscountStrategy discountStrategy) {
        this.discountStrategy = discountStrategy;
    }
}
